package com.jilefojing.beans.enums;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.jilefojing.beans.pojos.Comment;
import com.jilefojing.beans.pojos.EArticle;
import com.jilefojing.beans.pojos.EAudio;
import com.jilefojing.beans.pojos.EBook;
import com.jilefojing.beans.pojos.EBookChapter;
import com.jilefojing.beans.pojos.EVideo;
import com.jilefojing.beans.pojos.base.BasePo;
import com.jilefojing.beans.pojos.enhanced.EnhancedComment;
import com.jilefojing.beans.pojos.enhanced.EnhancedEArticle;
import com.jilefojing.beans.pojos.enhanced.EnhancedEAudio;
import com.jilefojing.beans.pojos.enhanced.EnhancedEBook;
import com.jilefojing.beans.pojos.enhanced.EnhancedEBookChapter;
import com.jilefojing.beans.pojos.enhanced.EnhancedEVideo;
import com.jilefojing.beans.pojos.enhanced.base.BaseEnhanced;

/**
 * 
 * @author 作者 jgshun
 * @date 创建时间 2016年07月21日 15时40分56秒
 */
public enum ItemTypeEnumForSource {
	/**
	 * (short) 1, "视频"
	 */
	VIDEO((short) 1, "视频", EVideo.class, EnhancedEVideo.class),
	/**
	 * (short) 2, "音频"
	 */
	AUDIO((short) 2, "音频", EAudio.class, EnhancedEAudio.class),
	/**
	 * (short) 3, "文本"
	 */
	TEXT((short) 3, "文本", null, null),
	/**
	 * (short) 4, "评论"
	 */
	COMMENT((short) 4, "评论", Comment.class, EnhancedComment.class),
	/**
	 * (short) 5, "经书"
	 */
	BOOK((short) 5, "经书", EBook.class, EnhancedEBook.class),
	/**
	 * (short) 6, "经书章节"
	 */
	BOOK_CHAPTER((short) 6, "经书章节", EBookChapter.class,
			EnhancedEBookChapter.class),
	/**
	 * (short) 7, "文章", EArticle.class, EnhancedEArticle.class
	 */
	ARTICLE((short) 7, "文章", EArticle.class, EnhancedEArticle.class),

	// /**
	// * (short) 8, "抄经", EBookChapter.class, EnhancedEBookChapter.class
	// */
	// BOOK_CHAPTER_WRITED((short) 8, "抄经", EBookChapter.class,
	// EnhancedEBookChapter.class)
	;

	private short code;
	private String msg;
	private Class<? extends BasePo> itemClass;
	private Class<? extends BaseEnhanced> enhancedItemClass;

	private ItemTypeEnumForSource(short code, String msg,
			Class<? extends BasePo> itemClass,
			Class<? extends BaseEnhanced> enhancedItemClass) {
		this.code = code;
		this.msg = msg;
		this.itemClass = itemClass;
		this.enhancedItemClass = enhancedItemClass;
	}

	public short getCode() {
		return code;
	}

	public void setCode(short code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Class<? extends BasePo> getItemClass() {
		return itemClass;
	}

	public void setItemClass(Class<? extends BasePo> itemClass) {
		this.itemClass = itemClass;
	}

	public Class<? extends BaseEnhanced> getEnhancedItemClass() {
		return enhancedItemClass;
	}

	public void setEnhancedItemClass(
			Class<? extends BaseEnhanced> enhancedItemClass) {
		this.enhancedItemClass = enhancedItemClass;
	}

	@Override
	public String toString() {
		if (this != null) {
			Map<String, Object> allMap = new HashMap<String, Object>();
			allMap.put("code", this.code);
			allMap.put("msg", this.msg);
			String result = JSONObject.toJSONString(allMap);
			result = result.replaceAll("\"", "'");
			return result;
		}
		return super.toString();
	}

	public static ItemTypeEnumForSource getItemTypeEnumByCode(short code) {
		for (ItemTypeEnumForSource _enum : ItemTypeEnumForSource.values()) {
			if (_enum.getCode() == code) {
				return _enum;
			}
		}
		return null;
	}

	public static ItemTypeEnumForSource getItemTypeEnumByEnhancedItemClass(
			Class<? extends BaseEnhanced> enhancedItemClass) {
		for (ItemTypeEnumForSource _enum : ItemTypeEnumForSource.values()) {
			if (_enum.getEnhancedItemClass() == enhancedItemClass) {
				return _enum;
			}
		}
		return null;
	}
}
